home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 17 / CU Amiga Magazine's Super CD-ROM 17 (1997)(EMAP Images)(GB)[!][issue 1997-12].iso / CUCD / Programming / DiceSource / src / das / lab.c < prev    next >
C/C++ Source or Header  |  1997-09-09  |  1KB  |  67 lines

  1. /*
  2.  *    (c)Copyright 1992-1997 Obvious Implementations Corp.  Redistribution and
  3.  *    use is allowed under the terms of the DICE-LICENSE FILE,
  4.  *    DICE-LICENSE.TXT.
  5.  */
  6.  
  7. /*
  8.  *  LAB.C
  9.  *
  10.  */
  11.  
  12. #include "defs.h"
  13.  
  14. Prototype   Label   *LabHash[LSIZE];
  15.  
  16. Prototype int    labhash(ubyte *);
  17. Prototype Label *GetLabelByName(char *);
  18. Prototype Label *FindLabel(char *);
  19.  
  20. Label    *LabHash[LSIZE];
  21.  
  22. int
  23. labhash(str)
  24. ubyte *str;
  25. {
  26.     register long hv = 0x1B465D8;
  27.  
  28.     while (*str)
  29.     hv = (hv >> 23) ^ (hv << 5) ^ *str++;
  30.     return(hv & LMASK);
  31. }
  32.  
  33. Label *
  34. GetLabelByName(name)
  35. char *name;
  36. {
  37.     long i = labhash(name);
  38.     Label **plab;
  39.     Label *lab;
  40.  
  41.     for (plab = LabHash + i; (lab = *plab) != NULL; plab = &lab->HNext) {
  42.     if (strcmp(lab->Name, name) == 0)
  43.         return(lab);
  44.     }
  45.     lab = AllocStructure(Label);
  46.     lab->HNext = *plab;
  47.     lab->Name = name;
  48.     lab->XDefLink = (void *)-1L;
  49.     *plab = lab;
  50.     return(lab);
  51. }
  52.  
  53. Label *
  54. FindLabel(name)
  55. char *name;
  56. {
  57.     long i = labhash(name);
  58.     Label *lab;
  59.  
  60.     for (lab = LabHash[i]; lab; lab = lab->HNext) {
  61.     if (strcmp(lab->Name, name) == 0)
  62.         return(lab);
  63.     }
  64.     return(lab);
  65. }
  66.  
  67.